﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["id"] == "" || Request.QueryString["id"] == null)
        {
            string jinggao3 = "<SCRIPT language=javascript>alert('";
            jinggao3 += "参数错误！";
            jinggao3 += "');</SCRIPT>";
            ClientScript.RegisterStartupScript(this.GetType(), "aa3", jinggao3);
            ClientScript.RegisterStartupScript(this.GetType(), "aa4", "<SCRIPT language=javascript>document.location.href='index.aspx';</SCRIPT>");
        }

    }


    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#D1DDF1'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
        }
        //if (Label1.Text == "材料科已受理")
        if (Convert.ToInt32(GridView2.Rows[0].Cells[21].Text) > 0)
        {
            double heji = 0, hejib = 0, hejic = 0, hejif = 0, hejiq = 0;
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                for (int j = 0; j <= GridView1.Rows.Count - 1; j++)
                {
                    GridViewRow row = this.GridView1.Rows[j];
                    heji += Convert.ToInt32(row.Cells[11].Text.ToString()) * Convert.ToDouble(row.Cells[8].Text.ToString());
                    hejib += Convert.ToInt32(row.Cells[9].Text.ToString()) * Convert.ToDouble(row.Cells[8].Text.ToString());
                    hejic += Convert.ToInt32(row.Cells[10].Text.ToString()) * Convert.ToDouble(row.Cells[8].Text.ToString());
                    hejif += Convert.ToInt32(row.Cells[13].Text.ToString()) * Convert.ToDouble(row.Cells[8].Text.ToString());
                    hejiq += Convert.ToInt32(row.Cells[16].Text.ToString()) * Convert.ToDouble(row.Cells[8].Text.ToString());
                }
                if (Convert.ToInt32(GridView2.Rows[0].Cells[21].Text) == 1)
                {
                    e.Row.Cells[8].Text = "班组总计";
                    e.Row.Cells[9].Text = hejib.ToString() + "元";
                    e.Row.Cells[10].Text = "材料科未核价";
                    e.Row.Cells[8].ForeColor = System.Drawing.Color.Red;
                    e.Row.Cells[9].ForeColor = System.Drawing.Color.Red;
                    e.Row.Cells[10].ForeColor = System.Drawing.Color.Red;
                    e.Row.Cells[11].ForeColor = System.Drawing.Color.Red;
                }
                else if (Convert.ToInt32(GridView2.Rows[0].Cells[21].Text) == 2)
                {
                    e.Row.Cells[8].Text = "总计";
                    e.Row.Cells[9].Text = "班组" + hejib.ToString() + "元";
                    e.Row.Cells[10].Text = "车间" + hejic.ToString() + "元";
                    e.Row.Cells[11].Text = "材料科未核价";
                    e.Row.Cells[8].ForeColor = System.Drawing.Color.Red;
                    e.Row.Cells[9].ForeColor = System.Drawing.Color.Red;
                    e.Row.Cells[10].ForeColor = System.Drawing.Color.Red;
                    e.Row.Cells[11].ForeColor = System.Drawing.Color.Red;
                }
                else if (Convert.ToInt32(GridView2.Rows[0].Cells[21].Text) > 2)
                {
                    e.Row.Cells[8].Text = "总计";
                    e.Row.Cells[9].Text = "班组" + hejib.ToString() + "元";
                    e.Row.Cells[10].Text = "车间" + hejic.ToString() + "元";
                    e.Row.Cells[11].Text = "段" + heji.ToString() + "元";
                    if (Convert.ToInt32(GridView2.Rows[0].Cells[21].Text) ==4)
                    {
                        e.Row.Cells[12].Text = "材料科未核价";
                        e.Row.Cells[8].ForeColor = System.Drawing.Color.Red;
                        e.Row.Cells[9].ForeColor = System.Drawing.Color.Red;
                        e.Row.Cells[10].ForeColor = System.Drawing.Color.Red;
                        e.Row.Cells[11].ForeColor = System.Drawing.Color.Red;
                        e.Row.Cells[12].ForeColor = System.Drawing.Color.Red;
                    }
                    //if (Convert.ToInt32(GridView2.Rows[0].Cells[21].Text) == 5)
                    else
                    {
                        e.Row.Cells[11].ForeColor = System.Drawing.Color.Yellow;
                    }
                }
                if (Convert.ToInt32(GridView2.Rows[0].Cells[21].Text) >= 6)
                {
                    e.Row.Cells[13].Text = "发料" + hejif.ToString() + "元";
                    e.Row.Cells[13].ForeColor = System.Drawing.Color.Orange;
                }
                if (Convert.ToInt32(GridView2.Rows[0].Cells[21].Text) >= 7)
                {
                    e.Row.Cells[16].Text = "签收" + hejiq.ToString() + "元";
                    e.Row.Cells[16].ForeColor = System.Drawing.Color.Tomato;
                }

            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.Cells[8].Text == "0")
                {
                    e.Row.ForeColor = System.Drawing.Color.FromArgb(0, 128, 255);
                }
                if (Convert.ToInt32(GridView2.Rows[0].Cells[21].Text) >= 6)
                {
                    if (Convert.ToInt32(e.Row.Cells[13].Text) < Convert.ToInt32(e.Row.Cells[11].Text))
                    {
                        e.Row.Cells[13].Font.Bold = true;
                        e.Row.Cells[13].ForeColor = System.Drawing.Color.Orange;
                        e.Row.Cells[14].Font.Bold = true;
                        e.Row.Cells[14].ForeColor = System.Drawing.Color.Orange;
                        //e.Row.Cells[15].Font.Bold = true;
                        e.Row.Cells[15].ForeColor = System.Drawing.Color.Orange;
                        //e.Row.ForeColor = System.Drawing.Color.HotPink;
                    }
                }
                if (Convert.ToInt32(GridView2.Rows[0].Cells[21].Text) >= 7)
                {
                    if (Convert.ToInt32(e.Row.Cells[16].Text) < Convert.ToInt32(e.Row.Cells[13].Text))
                    {
                        e.Row.Cells[16].Font.Bold = true;
                        e.Row.Cells[16].ForeColor = System.Drawing.Color.Tomato;
                        e.Row.Cells[17].Font.Bold = true;
                        e.Row.Cells[17].ForeColor = System.Drawing.Color.Tomato;
                        //e.Row.Cells[18].Font.Bold = true;
                        e.Row.Cells[18].ForeColor = System.Drawing.Color.Tomato;
                        //e.Row.ForeColor = System.Drawing.Color.HotPink;
                    }
                }
            }
        }
        //else
        //{
        //    if (e.Row.RowType == DataControlRowType.Footer)
        //    {
        //        e.Row.Cells[10].Text = "总计";
        //        e.Row.Cells[11].Text = "材料科未核价";
        //    }
        //    if (e.Row.RowType == DataControlRowType.DataRow)
        //    {
        //        //e.Row.Cells[8].Text = "材料科未核价";
        //    }
        //}
        if (e.Row.RowIndex != -1)
        {
            int id = e.Row.RowIndex + 1;
            e.Row.Cells[0].Text = id.ToString();
            e.Row.Cells[6].Text = e.Row.Cells[6].Text.Replace("&amp;#215;", "×").Replace("&amp;quot;", "");
            if (Convert.ToInt32(GridView2.Rows[0].Cells[21].Text) >= 4)
            {
                if (e.Row.Cells[11].Text == "0")
                {
                    e.Row.ForeColor = System.Drawing.Color.FromArgb(0, 128, 255);
                }
            }
        }
        this.GridView1.Attributes.Add("bordercolor", "#bbddff");
    }
    protected void GridView2_DataBound(object sender, EventArgs e)
    {
        Label2.Text = GridView2.Rows[0].Cells[3].Text;
        Label3.Text = GridView2.Rows[0].Cells[1].Text;
        Label_shijian.Text = GridView2.Rows[0].Cells[4].Text + "年" + GridView2.Rows[0].Cells[5].Text + "月";
        if (GridView2.Rows.Count >= 1)
        {
            switch (GridView2.Rows[0].Cells[21].Text)
            {
                case "0":
                    Label1.Text = "班组未提报";
                    break;
                case "1":
                    Label1.Text = "车间未审批";
                    Label_tibao.Text = "提报人：" + GridView2.Rows[0].Cells[6].Text + "   时间：" + GridView2.Rows[0].Cells[7].Text;
                    break;
                case "2":
                    Label1.Text = "段未审批";
                    Label_tibao.Text = "提报人：" + GridView2.Rows[0].Cells[6].Text + "   时间：" + GridView2.Rows[0].Cells[7].Text;
                    Label_chejian.Visible = true;
                    Label_chejian.Text = "车间审批：" + GridView2.Rows[0].Cells[9].Text + "   时间：" + GridView2.Rows[0].Cells[10].Text;
                    break;
                case "3":
                    Label1.Text = "段领导未审批";
                    break;
                case "4":
                    Label_tibao.Text = "提报人：" + GridView2.Rows[0].Cells[6].Text + "   时间：" + GridView2.Rows[0].Cells[7].Text;
                    Label1.Text = "段已审批，材料科未受理";
                    Label_chejian.Visible = true;
                    Label_chejian.Text = "车间审批：" + GridView2.Rows[0].Cells[9].Text + "   时间：" + GridView2.Rows[0].Cells[10].Text;
                    Label_duan.Visible = true;
                    Label_duan.Text = "段审批：" + GridView2.Rows[0].Cells[12].Text + "   时间：" + GridView2.Rows[0].Cells[13].Text;
                    break;
                case "5":
                    Label1.Text = "材料科已受理";
                    Label_tibao.Text = "提报人：" + GridView2.Rows[0].Cells[6].Text + "   时间：" + GridView2.Rows[0].Cells[7].Text;
                    Label_chejian.Visible = true;
                    Label_chejian.Text = "车间审批：" + GridView2.Rows[0].Cells[9].Text + "   时间：" + GridView2.Rows[0].Cells[10].Text;
                    Label_duan.Visible = true;
                    Label_duan.Text = "段审批：" + GridView2.Rows[0].Cells[12].Text + "   时间：" + GridView2.Rows[0].Cells[13].Text;
                    Label_cailiao.Visible = true;
                    Label_cailiao.Text = "材料科受理：" + GridView2.Rows[0].Cells[15].Text + "   时间：" + GridView2.Rows[0].Cells[16].Text;
                    break;
                case "6":
                    Label1.Text = "材料科已发料";
                    Label_tibao.Text = "提报人：" + GridView2.Rows[0].Cells[6].Text + "   时间：" + GridView2.Rows[0].Cells[7].Text;
                    Label_chejian.Visible = true;
                    Label_chejian.Text = "车间审批：" + GridView2.Rows[0].Cells[9].Text + "   时间：" + GridView2.Rows[0].Cells[10].Text;
                    Label_duan.Visible = true;
                    Label_duan.Text = "段审批：" + GridView2.Rows[0].Cells[12].Text + "   时间：" + GridView2.Rows[0].Cells[13].Text;
                    Label_cailiao.Visible = true;
                    Label_cailiao.Text = "材料科受理：" + GridView2.Rows[0].Cells[15].Text + "   时间：" + GridView2.Rows[0].Cells[16].Text;
                    Label_faliao.Visible = true;
                    Label_faliao.Text = "材料科发料：" + GridView2.Rows[0].Cells[23].Text + "   时间：" + GridView2.Rows[0].Cells[24].Text;
                    break;
                case "7":
                    Label1.Text = "材料部分签收";
                    Label_tibao.Text = "提报人：" + GridView2.Rows[0].Cells[6].Text + "   时间：" + GridView2.Rows[0].Cells[7].Text;
                    Label_chejian.Visible = true;
                    Label_chejian.Text = "车间审批：" + GridView2.Rows[0].Cells[9].Text + "   时间：" + GridView2.Rows[0].Cells[10].Text;
                    Label_duan.Visible = true;
                    Label_duan.Text = "段审批：" + GridView2.Rows[0].Cells[12].Text + "   时间：" + GridView2.Rows[0].Cells[13].Text;
                    Label_cailiao.Visible = true;
                    Label_cailiao.Text = "材料科受理：" + GridView2.Rows[0].Cells[15].Text + "   时间：" + GridView2.Rows[0].Cells[16].Text;
                    Label_faliao.Visible = true;
                    Label_faliao.Text = "材料科发料：" + GridView2.Rows[0].Cells[23].Text + "   时间：" + GridView2.Rows[0].Cells[24].Text;
                    Label_qianshou.Visible = true;
                    Label_qianshou.Text = "签收人：" + GridView2.Rows[0].Cells[26].Text + "   时间：" + GridView2.Rows[0].Cells[27].Text;
                    break;
                case "8":
                    Label1.Text = "材料全部签收";
                    Label_tibao.Text = "提报人：" + GridView2.Rows[0].Cells[6].Text + "   时间：" + GridView2.Rows[0].Cells[7].Text;
                    Label_chejian.Visible = true;
                    Label_chejian.Text = "车间审批：" + GridView2.Rows[0].Cells[9].Text + "   时间：" + GridView2.Rows[0].Cells[10].Text;
                    Label_duan.Visible = true;
                    Label_duan.Text = "段审批：" + GridView2.Rows[0].Cells[12].Text + "   时间：" + GridView2.Rows[0].Cells[13].Text;
                    Label_cailiao.Visible = true;
                    Label_cailiao.Text = "材料科受理：" + GridView2.Rows[0].Cells[15].Text + "   时间：" + GridView2.Rows[0].Cells[16].Text;
                    Label_faliao.Visible = true;
                    Label_faliao.Text = "材料科发料：" + GridView2.Rows[0].Cells[23].Text + "   时间：" + GridView2.Rows[0].Cells[24].Text;
                    Label_qianshou.Visible = true;
                    Label_qianshou.Text = "签收人：" + GridView2.Rows[0].Cells[26].Text + "   时间：" + GridView2.Rows[0].Cells[27].Text;
                    break;
                default:
                    break;
            }
        }
    }
}